package com.hqyj.controller;

import com.hqyj.pojo.ManagerInfo;
import com.hqyj.pojo.Resultinfo;
import com.hqyj.pojo.UserSerInfo;
import com.hqyj.service.UserSerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.websocket.Session;
import java.util.Enumeration;
import java.util.HashMap;

@Controller
@RequestMapping("/userser")
public class UserSerInfoController {
    @Autowired
    UserSerService userSerService;
    @RequestMapping("/list")
    public String list(Resultinfo user, ModelMap m,HttpSession session){
        //把当前用户参数传入
        ManagerInfo managerInfo= (ManagerInfo) session.getAttribute("mag");
        System.out.print(managerInfo.getManagerNickName()+"********************************************************");
        user.setSerManager(managerInfo.getManagerNickName());
        //查训分页数据
        HashMap<String, Object> map= userSerService.select(user);
        //把数据传到前端
        m.put("info",map);
        m.put("vv",user.getConValue());
        return "manager/manager-list";
    }
    //处理查询表格的ajax数据
    @RequestMapping("/listAjax")
    @ResponseBody
    public HashMap<String,Object> listAjax(Resultinfo user){
        HashMap<String,Object> map = new HashMap<>();
        return userSerService.select(user);
    }
    //打开修改页面
    @RequestMapping("/editpage")
    public String editpage(Resultinfo user, ModelMap m){
        //打开修改页面
        //根据userid查询

        Resultinfo u = userSerService.selectByUserId(user);
        //把数据传递到前端
        m.addAttribute("user",u);
        return "manager/manager-editresult";
    }
    //处理修改的ajax请求
    @RequestMapping("/edit")
    @ResponseBody
    public HashMap<String,Object> edit(Resultinfo user){
        HashMap<String,Object> map = new HashMap<>();
        String info =userSerService.wanchen(user);

        map.put("info",info);
        return map;
    }
    //处理修改的ajax请求
    @RequestMapping("/del")
    @ResponseBody
    public HashMap<String,Object> del(Resultinfo user){
        HashMap<String,Object> map = new HashMap<>();
        String info1 =userSerService.del1(user);
        String info =userSerService.del(user);
        map.put("info",info);
        map.put("info1",info1);
        return map;
    }
}
